package cn.itcast.order;

import cn.itcast.feign.cilents.UserClient;
import cn.itcast.feign.config.FeignClientConfiguration;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@MapperScan("cn.itcast.order.mapper")
@SpringBootApplication
//@EnableFeignClients(defaultConfiguration = FeignClientConfiguration.class)    // 开启feign客户端并开启日志输出
@EnableFeignClients(clients = {UserClient.class})   // 开启feign客户端
public class OrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
    }


    //创建RestTemplate对象  远程调用用户信息
    @Bean
    @LoadBalanced    //开启负载均衡
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

//    @Bean  // 自定义负载均衡规则
//    public IRule randomRule(){
//        return new RandomRule();
//    }
}